@extends('layout.layout')

@section('content')
    <h1 class="page-title">分类管理 <small></small></h1>
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget">
                    <div class="widget">
                        <div class="widget-header">
                            <h4>分类列表</h4>
 
                        </div>
                        <div class="widget-content">
                        <div class="row-fluid">
                           <div class="span6">
                           <form action="">
                            <div class="dataTables_length" id="data-table_length">
                             <label><select aria-controls="data-table" size="1" name="num" style="background: rgba(0,0,0,0.5)">
                             <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
                             <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
                             <option value="50" @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
                             </select>每页显示条数</label>
                            </div>
                           </div>
                           <div class="span6">
                            <div id="data-table_filter" class="dataTables_filter">
                             <label>分类名 <input name="keywords" value="@if(!empty($request['keywords'])){{$request['keywords']}}@endif" aria-controls="data-table" type="text"/>
                             <button class="btn btn-primary icon-search" type="submit" style="position:relative;bottom:4px;">查询</button>
                             </label>
                            </div>
                           </div>
                           <input type="hidden" name="_token" value="{{csrf_token()}}"/>
                           </form>
                          </div>
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th class="hidden-phone">分类名</th>
                                        <th class="hidden-phone">父级分类</th>
                                        <th class="hidden-phone" >状态</th>
                                        <th style="width: 111px;">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                @foreach($cates as $k=>$v)
                                    <tr class="odd gradeX">
                                        <td class="sid">{{$v->id}}</td>
                                        <td class="hidden-phone">{{$v->name}}</td>
                                        <td class="hidden-phone">{{$v->path}}</td>
                                        <td class="center hidden-phone">
                                        @if($v->status == 1)
                                            <span class="label label-success">启用</span>
                                            @elseif($v->status != 1)
                                            <span class="label label-important">未启用</span>
                                        @endif
                                        </td>
                                        <td class="center hidden-phone">
                                        <span class="icon-remove label label-important">
                                        <a href = "" class="delete"> 删除</a>
                                        {{csrf_field()}}
                                        </span>
                                        &nbsp;&nbsp;
                                        <span class="icon-edit label label-success">
                                        <a href = "{{url('admin/cate/edit',['id'=>$v->id])}}">修改</a>
                                        </span>
                                        </td>
                                    </tr>
                                @endforeach   
                                </tbody>
                            </table>
                            <!-- 分页 -->
                            <div class="row-fluid">
                               <div class="span6">
                                <div id="data-table_info" class="dataTables_info padding-top-25">
                                共&nbsp;<span class="badge badge-info">{!! $cates->total() !!}</span>&nbsp;条
                                </div>
                               </div>
                               <div class="span6">
                                <div class="dataTables_paginate paging_bootstrap pagination padding-bottom-20">
                                 {!! $cates->appends($request)->render() !!}
                                </div>
                               </div>
                              </div>
                              <!-- 分页eend -->
                            <div class="clearfix"></div>
                        </div>
                    </div>
                    </div>
                </div><!-- end span12 -->
            </div><!-- end row-fluid -->
@endsection
@section('myjs')
    <!-- 无刷新删除 -->
    <script type="text/javascript">
    // alert($);
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $('.delete').click(function(){
        var id = $(this).parents('tr').find('.sid').html();
        // alert('222');
        var dd = $(this);
        // 发送ajax
        $.post('/admin/cate/delete',{id:id},function(data){
            if(data == 2){
                dd.parents('tr').remove();
                message('success','分类删除成功!!');
            }else if(data == 1){
                message('error','当前分类下有子分类,不能删除!');
            }else{
                message('error','删除失败');
            }
        })
        return false;
    })

    // 封装函数显示信息
    function message(er,m){
        console.log(m);
        if(er == 'success'){
            $('#messagesuccess').find('span').text(m);
            $('#messagesuccess').show();
        }else{
            $('#messagedanger').find('span').text(m);
            $('#messagedanger').show();
        }
    }
    </script>
@endsection